package com.rf.converter;

import org.springframework.core.convert.converter.Converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Description 类型转换类
 * @Author hxj
 * @Date 2022/3/31 15:39 星期四
 */
public class StringToDateConverter implements Converter<String, Date> {

    @Override
    public Date convert(String dateStr) {
        Date result = null;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        try {
            //解析一个日期字符串
            result = simpleDateFormat.parse(dateStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return result;
    }

}
